<template>
  <el-dialog
    v-el-drag-dialog
    :title="type === 1 ? '商品调拨' : `调拨单编辑`+(temp.stockTransCode?'--'+temp.stockTransCode:'')"
    :visible.sync="visible"
    width="1400px"
    @closed="reset"
  >
    <el-form
      ref="dataForm"
      class="dataForm"
      :inline="true"
      label-width="100px"
      :model="temp"
      :rules="rules"
    >
      <el-form-item label="调拨类型" prop="transType">
        <el-select v-model="temp.transType" placeholder="请选择" clearable>
          <el-option
            v-for="item in transTypeMap"
            :key="item.value"
            :label="item.desc"
            :value="item.value"
          />
        </el-select>
      </el-form-item>

      <el-form-item label="仓库(出)" prop="outStoreId">
        <el-select v-model="temp.outStoreId" filterable placeholder="请选择" clearable @change="outChange">
          <el-option
            v-for="item in leftStoreMap"
            :key="item.storeId"
            :label="item.storeName"
            :value="item.storeId"
          />
        </el-select>
      </el-form-item>
      <el-form-item :table-form-merge="0.3">
        <el-button
          circle
          type="primary"
        ><svg-icon
          class="map"
          icon-class="exchange"
          @click="exchange"
        /></el-button>
      </el-form-item>
      <el-form-item label="仓库(入)" prop="inStoreId">
        <el-select v-model="temp.inStoreId" filterable placeholder="请选择" clearable @change="inChange">
          <el-option
            v-for="item in RightStoreMap"
            :key="item.storeId"
            :label="item.storeName"
            :value="item.storeId"
          />
        </el-select>
      </el-form-item>

      <el-form-item label="调拨车辆" prop="carNumber">
        <el-select v-model="temp.carNumber" filterable placeholder="请选择" clearable @change="truckChange">
          <el-option
            v-for="item in truckMap"
            :key="item.truckId"
            :label="item.truckCode"
            :value="item.truckId"
          />
        </el-select>
      </el-form-item>

      <el-form-item label="司机" prop="driverId">
        <el-select v-model="temp.driverId" filterable placeholder="请选择" clearable @change="driverChange">
          <el-option
            v-for="item in driverMap"
            :key="item.userId"
            :label="item.userName"
            :value="item.userId"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="押运员" prop="escortId">
        <el-select v-model="temp.escortId" filterable placeholder="请选择" clearable @change="escortChange">
          <el-option
            v-for="item in escortMap"
            :key="item.userId"
            :label="item.userName"
            :value="item.userId"
          />
        </el-select>
      </el-form-item>

      <el-form-item label="调拨扫瓶" prop="isSweep" label-width="145px">
        <el-select v-model="temp.isSweep" placeholder="请选择" clearable :disabled="disablesweep">
          <el-option
            v-for="item in isSweepMap"
            :key="item.value"
            :label="item.desc"
            :value="item.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="结算金额" prop="settlementAmount">
        <el-input-number
          v-model="temp.settlementAmount"
          :controls="false"
          :min="0"
          placeholder="请输入"
          clearable
          style="width: 199px;"
        />
      </el-form-item>
      <el-form-item label="期望时间" prop="expectDt" class="merge-item">
        <el-date-picker
          v-model="temp.expectDt"
          type="date"
          value-format="yyyy-MM-dd"
          :clearable="false"
        />
      </el-form-item>
      <el-form-item label="备注" class="remark-item">
        <el-input
          v-model="temp.remark"
          placeholder="请输入"
          clearable
          maxlength="200"
          show-word-limit
        />
      </el-form-item>
    </el-form>

    <el-row :gutter="10">
      <el-col :span="10">
        <div class="so">
          <el-input
            v-model="goodsName"
            placeholder="请输入商品名称"
            class="input-with-select"
          >
            <el-button
              slot="append"
              type="primary"
              icon="el-icon-search"
              @click="tableLeftFetchData"
            >搜索</el-button>
          </el-input>
        </div>

        <el-row>
          <el-col :span="8">
            <!-- <goods-tree
              class="leftTree"
              title="商品分类"
              :tree-data="treeData"
              :loading="$loadingPlugin.getTreeData"
              :mouse-button="false"
              @currentChange="currentChange"
            /> -->
          </el-col>
          <el-col :span="24">
            <lb-table
              ref="lbTableLeft"
              border
              class="leftTable"
              highlight-current-row
              element-loading-text="加载中"
              :column="tableLeftData.column"
              :data="tableLeftData.data"
              @current-change="tableLeftChange"
            />
          </el-col>
        </el-row>
      </el-col>
      <el-col :span="lbTableRightwidth">
        <lb-table
          ref="lbTableRight"
          border
          class="rightTable"
          element-loading-text="加载中"
          :column="tableRightData.column"
          :data="tableRightData.data"
        />
        <div v-show="totalCount!==0||totalWeight!==0" class="total">本次调拨合计{{ totalCount }}瓶</div>
      </el-col>
    </el-row>
    <div slot="footer" class="dialog-footer">
      <el-button :loading="$loadingPlugin.add" type="primary" @click="save">保存</el-button>
      <el-button @click="visible = false">关闭</el-button>
    </div>
  </el-dialog>
</template>

<script>
  import { mapGetters } from 'vuex'
  import getTreeData from '@/utils/jsonTree'
  // import GoodsTree from '@/views/components/GoodsTypeTree'
  import { formatColumnMap } from '@/utils'
  import { goodsTypeQueryAllList, stockTransAdd, goodsSortList, selectOrgSNNo } from '@/api'
  // goodsTypeDetailList,
  const JINJIANG = 58 // 晋江城市标识

  export default {
    name: 'allot',
    components: {
      // GoodsTree
    },
    props: {
      transTypeMap: {
        type: Array,
        required: true
      },
      storeMap: {
        type: Array,
        required: true
      },
      truckMap: {
        type: Array,
        required: true
      },
      driverMap: {
        type: Array,
        required: true
      },
      escortMap: {
        type: Array,
        required: true
      }
    },
    data() {
      return {
        visible: false,
        temp: {
          transType: 2,
          outStoreId: '',
          inStoreId: '',
          carNumber: '',
          driverId: '',
          escortId: '',
          isSweep: '',
          settlementAmount: undefined,
          expectDt: new Date(),
          remark: ''
        },
        leftStoreMap: [],
        RightStoreMap: [],
        storageStoreMap: [],
        isSweepMap: [{ desc: '否', value: 1 }, { desc: '是', value: 2 }],
        treeData: [],
        goodsName: '',
        goodsData: {}, // 商品分类数据
        lbTableRightwidth: 14,
        rules: {
          transType: [{ required: true, message: '请选择调拨类型', trigger: 'change' }],
          outStoreId: [{ required: true, message: '请选择调出仓库', trigger: 'change' }],
          inStoreId: [{ required: true, message: '请选择调入仓库', trigger: 'change' }],
          carNumber: [{ required: false, message: '请选择调拨车辆', trigger: 'change' }],
          driverId: [{ required: false, message: '请选择司机', trigger: 'change' }],
          isSweep: [{ required: true, message: '请选择调拨扫瓶', trigger: 'change' }]

        },
        gdStatusMap: [],
        // 左侧列表
        tableLeftData: {
          column: [
            {
              prop: 'goodsName',
              label: '商品名称'
            },
            {
              prop: 'specName',
              label: '规格型号'
            },
            {
              prop: 'unitName',
              label: '单位'
            }
          ],
          data: []
        },
        // 右侧列表
        tableRightData: {
          column: [
            {
              prop: 'goodsName',
              label: '商品名称',
              width: 120
            },
            {
              prop: 'goodsSpec',
              label: '规格型号'
            },
            {
              prop: 'unitName',
              label: '单位'
            },
            {
              prop: 'gdStatus',
              label: '状态',
              width: 180,
              render: (h, scope) => {
                return (
                <div>
                  {scope.row._edit ? (
                    <el-select
                      value={scope.row[scope.column.property]}
                      style='width: 140px'
                      onChange={(val) => {
                        scope.row[scope.column.property] = val
                      }}
                    >
                      {scope.row.gdStatusMap.map((option) => {
                        return (
                          <el-option label={option.desc} value={option.value}></el-option>
                        )
                      })}
                    </el-select>
                  ) : (
                    <span>
                      {scope.row[scope.column.property] &&
                        formatColumnMap(
                          this.transStatusMap,
                          'value',
                          scope.row[scope.column.property],
                          'desc'
                        )}
                    </span>
                  )}
                </div>
                )
              }
            },
            {
              prop: 'gdCount',
              label: '数量',
              render: (h, scope) =>
                (scope.row._edit && scope.row['pricingMode'] === 1) ? (
                <el-input
                  maxlength={10}
                  v-model={scope.row[scope.column.property]}
                  onInput={(val) =>
                    (scope.row[scope.column.property] = val
                      .replace(/[^\d.]/g, '')
                      .replace(/^0\d+|^\./g, '')
                      .replace(/\.{2,}/g, '.')
                      .replace('.', '$#$')
                      .replace(/\./g, '')
                      .replace('$#$', '.')
                      .replace(/^(.*\..{2}).*$/, '$1'))
                  }
                  size='mini'
                />
                  ) : (
                <span>{scope.row[scope.column.property]}</span>
              )
            },
            {
              prop: 'netWeight',
              label: '重量',
              width: 100,
              render: (h, scope) =>
                (scope.row._edit && scope.row['pricingMode'] === 2) ? (
                <el-input
                  maxlength={10}
                  v-model={scope.row[scope.column.property]}
                  onInput={(val) =>
                    (scope.row[scope.column.property] = val
                      .replace(/[^\d.]/g, '')
                      .replace(/^0\d+|^\./g, '')
                      .replace(/\.{2,}/g, '.')
                      .replace('.', '$#$')
                      .replace(/\./g, '')
                      .replace('$#$', '.')
                      .replace(/^(.*\..{2}).*$/, '$1'))
                  }
                  size='mini'
                />
                  ) : (
                <span>{scope.row[scope.column.property]}</span>
              )
            },
            // {
            //   prop: 'remark',
            //   label: '备注',
            //   width: 180,
            //   render: (h, scope) =>
            //     scope.row._edit ? (
            //     <el-input v-model={scope.row[scope.column.property]} size='mini' maxlength={40}/>
            //       ) : (
            //     <span>{scope.row[scope.column.property]}</span>
            //   )
            // },
            {
              label: '操作',
              width: '150px',
              fixed: 'right',
              render: (h, scope, $index) => {
                return (
                <div>
                  {scope.row._edit ? (
                    <div>
                      <el-link
                        type='primary'
                        underline={false}
                        size='mini'
                        onClick={() => this.handleSave(scope)}
                      >
                        保存
                      </el-link>
                      <el-link
                        type='primary'
                        underline={false}
                        size='mini'
                        onClick={() => this.handleDel(scope)}
                      >
                        删除
                      </el-link>
                    </div>
                  ) : (
                    <div>
                      <el-link
                        type='primary'
                        underline={false}
                        size='mini'
                        onClick={() => this.handleEdit(scope)}
                      >
                        编辑
                      </el-link>
                      <el-link
                        type='primary'
                        underline={false}
                        size='mini'
                        onClick={() => this.handleDel(scope)}
                      >
                        删除
                      </el-link>
                    </div>
                  )}
                </div>
                )
              }
            }
          ],
          data: [],
          defaultData: []
        },
        transStatusMap: [
          { value: 1, desc: '重', key: 'HEAVY' },
          { value: 2, desc: '空', key: 'LIGHT' },
          { value: 3, desc: '回收', key: 'RECYCLE' },
          { value: 4, desc: '故障', key: 'BROKEN' },
          { value: 5, desc: '已损坏', key: 'CORRUPT' },
          { value: 6, desc: '正常', key: 'NORMAL' },
          { value: 7, desc: '报废', key: 'SCRAPPED' },
          { value: 8, desc: '过期', key: 'EXPIRED' },
          { value: 9, desc: '问题重瓶', key: 'QUEHEAVY' },
          { value: 10, desc: '漏气', key: 'GAS_LEAK' },
          { value: 11, desc: '欠重', key: 'WEIGHT_SHORTAGE' },
          { value: 12, desc: '其他', key: 'OTHER' }
        ],
        type: 1,
        disablesweep: false,
        totalWeight: 0,
        totalCount: 0
      }
    },
    computed: {
      ...mapGetters([
        'userInfo', 'corpSettingData'
      ])
    },
    watch: {
      'corpSettingData.sp6': {
        handler(newVal, oldVal) {
          console.log('newVal', newVal)
          console.log('oldVal', oldVal)

          if (this.corpSettingData.sp6 >> 6 & 1) {
            this.temp.isSweep = 2
            this.disablesweep = true
          }
          if (this.corpSettingData.sp6 >> 7 & 1) {
            this.temp.isSweep = 1
            this.disablesweep = true
          }
          if (this.corpSettingData.sp6 >> 8 & 1) {
            this.temp.isSweep = ''
            this.disablesweep = false
          }
          console.log('isSweep', this.temp.isSweep)
          console.log(this.corpSettingData.sp6 >> 5 & 1)
          if (this.corpSettingData.sp6 >> 5 & 1 && this.userInfo.showRN !== JINJIANG) {
            this.rules.carNumber[0].required = false
            this.rules.driverId[0].required = false
          }
          // else {
          //   this.rules.carNumber[0].required = true
          //   this.rules.driverId[0].required = true
          // }
        },
        deep: true,
        immediate: true
      }
    },
    created() {
      if (this.userInfo.showRN === JINJIANG) {
        this.temp.transType = 3
        this.rules.driverId[0].required = true
      }
    },
    methods: {
      open(row) {
        this.getTreeData()
        this.leftStoreMap = JSON.parse(JSON.stringify(this.storeMap))
        this.temp.outStoreId = this.leftStoreMap[0] && this.leftStoreMap[0].storeId
        this.selectCursnno()
        return new Promise((resolve) => {
          this.resolve = resolve
          this.visible = true
        })
      },
      // 搜索按钮
      async tableLeftFetchData() {
        const res = await goodsSortList({
          gtId: this.goodsData.gtId,
          pageIndex: 1,
          goodsName: this.goodsName,
          pageSize: 999
        })
        if (this.corpSettingData.sp3 >> 6 & 0x01) {
          const list = res.data.rows.filter(item => {
            if (!item.options) {
              return true
            }
            if (item.options >> 1 & 0x01) {
              return false
            }
            if (item.options >> 2 & 0x01) {
              return false
            }
            return true
          })
          console.log('list', list)
          this.tableLeftData.data = list
        } else {
          if (this.goodsData.gtFlag === 1) {
            this.tableLeftData.data = res.data.rows.filter(item => item.pricingMode === 2)
          } else {
            this.tableLeftData.data = res.data.rows
          }
        }
      },
      async selectCursnno() {
        selectOrgSNNo({
          orgSNNo: '',
          reType: 4
        }).then(res => {
          const RightStoreMap = res.data.filter(item => {
            return item.reType === 1 || item.reType === 3 || item.reType === 6
          })
          this.RightStoreMap = RightStoreMap
          this.storageStoreMap = RightStoreMap
        })
      },
      tableLeftChange(row) {
        if (!row) {
          return
        }
        // console.log('row', row)
        const obj = {
          gtId: this.goodsData.gtId,
          gtSNNo: this.goodsData.gtSNNo,
          gtName: this.goodsData.gtName,
          goodsCode: row.goodsCode,
          goodsName: row.goodsName,
          goodsSpec: row.specName,
          specCode: row.specCode,
          unitId: row.unitId,
          unitName: row.unitName,
          tempGdStatus: row.gdStatus,
          goodsId: row.goodsId,
          gtFlag: this.goodsData.gtFlag,
          pricingMode: row.pricingMode,
          gdStatus: '', // 状态
          gdCount: '', // 数量
          netWeight: '', // 重量
          remark: '',
          _edit: true, // 是否编辑
          gdStatusMap: []
        }
        // 处理是已经增加过该商品
        var flag = []
        if (this.tableRightData.data.length) {
          flag = this.tableRightData.data.filter((item) => item.goodsId === obj.goodsId && item.gdStatus === obj.gdStatus)
        }
        if (flag.length) {
          this.$message({
            type: 'warning',
            message: `${obj.gtName}已存在`
          })
          return
        }
        console.log('obj', obj)
        // 为每行数据添加可供选择的状态
        obj.gdStatusMap = this.setGdStatusMap(obj)
        // 把当前的数据放在右边列表
        this.tableRightData.data.push(obj)
        console.log('增加后的数据', this.tableRightData.data)
      },
      // 商品分类
      async getTreeData() {
        const res = await goodsTypeQueryAllList()
        const data = res.data.map((item) => ({
          label: item.gtName,
          ...item
        }))
        this.treeData = getTreeData(data, 'parentId', 'gtId')
        const item = res.data.find(item => item.gtFlag === 2)
        this.currentChange(item)
      },
      // 商品分类事件
      async currentChange(current) {
        this.goodsData = current
        const goodsName = this.goodsName
        const res = await goodsSortList({
          gtId: current.gtId,
          pageIndex: 1,
          goodsName: goodsName,
          pageSize: 999
        })
        if (this.corpSettingData.sp3 >> 6 & 0x01) {
          const list = res.data.rows.filter(item => {
            if (!item.options) {
              return true
            }
            if (item.options >> 1 & 0x01) {
              return false
            }
            if (item.options >> 2 & 0x01) {
              return false
            }
            return true
          })
          console.log('list', list)
          this.tableLeftData.data = list
        } else {
          if (this.goodsData.gtFlag === 1) {
            this.tableLeftData.data = res.data.rows.filter(item => item.pricingMode === 2)
          } else {
            this.tableLeftData.data = res.data.rows
          }
        }
      },
      setGdStatusMap(row) {
        if (this.corpSettingData.sp3 >> 6 & 0x01) {
          if (row.pricingMode === 2) {
            return [{ value: 6, desc: '正常' }]
          } else {
            const datas = this.transStatusMap
            if (row.tempGdStatus) {
              const realItems = []
              for (var i in datas) {
                const item = datas[i]
                if ((row.tempGdStatus & 1 << item.value) > 0) {
                  realItems.push(item)
                }
              }
              return realItems
            } else {
              return datas
            }
          }
        } else {
          if (row.gtFlag === 3 || row.pricingMode === 2) {
            return [{ value: 6, desc: '正常' }]
          } else if (row.gtFlag <= 2) {
            const datas = this.transStatusMap
            if (row.tempGdStatus) {
              const realItems = []
              // eslint-disable-next-line no-redeclare
              for (var i in datas) {
                const item = datas[i]
                if ((row.tempGdStatus & 1 << item.value) > 0) {
                  realItems.push(item)
                }
              }
              console.log('realItems', realItems)
              return realItems
            } else {
              return datas
            }
          }
        }
      },
      exchange() {
        if (this.temp.inStoreId && this.temp.outStoreId) {
          const num1 = this.temp.inStoreId
          const num2 = this.temp.outStoreId
          this.inChange(num2)
          this.outChange(num1)
          const array1 = JSON.parse(JSON.stringify(this.RightStoreMap))
          this.RightStoreMap = JSON.parse(JSON.stringify(this.leftStoreMap))
          this.leftStoreMap = JSON.parse(JSON.stringify(array1))
        }
      },
      handleEdit(scope) {
        console.log(scope)
        console.log(this.tableRightData.data[scope.$index])
        this.$set(scope.row, '_edit', true)
        // this.$set(this.tableRightData.data[scope.$index], '_edit', true)
      },
      // 保存
      async handleSave(scope) {
        // 过滤重复增加该商品
        var flag = 0
        if (this.tableRightData.data.length) {
          const list = JSON.parse(JSON.stringify(this.tableRightData.data))
          flag = this.tableRightData.data.some((e) => list.filter((e1) => e1.goodsId === e.goodsId && e1.gdStatus === e.gdStatus).length > 1)
        }
        let repetitionItem = {}
        await this.tableRightData.data.forEach(item => {
          this.tableRightData.data.forEach(i => {
            if (item.goodsId === i.goodsId && item.gdStatus === i.gdStatus) {
              repetitionItem = item
            }
          })
        })
        if (flag) {
          this.$message({
            type: 'warning',
            message: `${repetitionItem.goodsName}（${formatColumnMap(
              repetitionItem.gdStatusMap,
              'value',
              repetitionItem.gdStatus,
              'desc'
            )}）商品已存在`
          })
          return
        }
        this.$set(scope.row, '_edit', false)
        this.$set(
          this.tableRightData.defaultData,
          scope.$index,
          JSON.parse(JSON.stringify(scope.row))
        )
        this.totalWeight = 0
        this.totalCount = 0
        this.tableRightData.defaultData.forEach(item => {
          if (item.pricingMode === 2) {
            this.totalWeight += Number(item.netWeight)
          }
          if (item.pricingMode === 1) {
            this.totalCount += Number(item.gdCount)
          }
        })
        console.log('totalWeight', this.totalWeight, 'totalCount', this.totalCount)
      },
      handleCancle(scope) {
        this.$set(
          this.tableRightData.data,
          scope.$index,
          JSON.parse(JSON.stringify(this.tableRightData.defaultData[scope.$index]))
        )
      },
      handleDel(scope) {
        const row = this.tableRightData.data
        const defaultRow = this.tableRightData.defaultData
        this.$delete(row, scope.$index)
        this.$delete(defaultRow, scope.$index)
      },
      save() {
        this.$refs.dataForm.validate(async(valid) => {
          if (valid) {
            // this.tableRightData.data.map((item) => (item._edit = false))
            if (this.temp.inStoreId === this.temp.outStoreId) {
              this.$message({
                type: 'error',
                message: `调出仓库和调入仓库不能相同`
              })
              return
            }
            // }
            // 处理押运员
            if (!this.temp.escortId) {
              this.$set(this.temp, 'escort', '')
              this.$set(this.temp, 'escortId', '')
            }
            if (!this.tableRightData.data.length) {
              this.$message({
                type: 'error',
                message: `请添加商品`
              })
              return
            }
            if ((this.corpSettingData.sp5 >> 9 & 0x01) > 0) {
              if (!this.temp.carId) {
                this.$message({
                  type: 'error',
                  message: `请选择配送车辆`
                })
                return
              }
              if (!this.temp.driverId) {
                this.$message({
                  type: 'error',
                  message: `请选择司机`
                })
                return
              }
            }
            // 处理是否有空数据
            for (var i = 0; i < this.tableRightData.data.length; i++) {
              if (this.tableRightData.data[i].gdStatus === '') {
                this.$message({
                  type: 'error',
                  message: `请选择${this.tableRightData.data[i].goodsName}的商品状态`
                })
                return
              }
              if (this.tableRightData.data[i]._edit) {
                this.$message({
                  type: 'error',
                  message: `请完成调拨商品的编辑`
                })
                return
              }
              // if (this.tableRightData.data[i].pricingMode === 2) {
              //   if (!this.tableRightData.data[i].specCode) {
              //     this.$message({
              //       type: 'warning',
              //       message: `请选择${this.tableRightData.data[i].gtName}的规格型号`
              //     })
              //     return
              //   }
              if (this.tableRightData.data[i].pricingMode === 2) {
                if (this.tableRightData.data[i].netWeight * 1 === 0) {
                  this.$message({
                    type: 'warning',
                    message: `请输入${this.tableRightData.data[i].goodsName}的重量`
                  })
                  return
                }
              }
              if (this.tableRightData.data[i].pricingMode === 1) {
                if (this.tableRightData.data[i].gdCount * 1 === 0) {
                  this.$message({
                    type: 'warning',
                    message: `请输入${this.tableRightData.data[i].goodsName}数量`
                  })
                  return
                }
              }
            }
            // const params = {
            //   ...this.temp,
            //   bottleNum: this.totalCount,
            //   detailList: this.tableRightData.data
            // }
            // const res = await stockTransAdd(params)
            // if (res.success) {
            //   this.$message({
            //     message: '操作成功！',
            //     type: 'success'
            //   })
            //   this.visible = false
            //   // 更新列表
            //   this.$emit('upDdataTable')
            // }
            this.add()
          } else {
            return false
          }
        })
      },

      async add() {
        const params = {
          ...this.temp,
          bottleNum: this.totalCount,
          detailList: this.tableRightData.data
        }
        const res = await stockTransAdd(params)
        if (res.success) {
          this.$message({
            message: '操作成功！',
            type: 'success'
          })
          this.visible = false
          // 更新列表
          this.$emit('upDdataTable')
        }
      },

      // 押运员
      escortChange(val) {
        if (val) {
          const arr = this.escortMap.find((l) => l.userId === val)
          this.$set(this.temp, 'escort', arr.userName)
          this.$set(this.temp, 'escortId', arr.userId)
        } else {
          this.$set(this.temp, 'escort', '')
          this.$set(this.temp, 'escortId', '')
        }
      },
      // 处理司机
      driverChange(val) {
        if (val) {
          const arr = this.driverMap.find((l) => l.userId === val)
          this.$set(this.temp, 'driver', arr.userName)
          this.$set(this.temp, 'driverId', arr.userId)
        } else {
          this.$set(this.temp, 'driver', '')
          this.$set(this.temp, 'driverId', '')
        }
      },
      // 车辆参数处理
      truckChange(val) {
        if (val) {
          const arr = this.truckMap.find((l) => l.truckId === val)
          this.$set(this.temp, 'carId', arr.truckId)
          this.$set(this.temp, 'carNumber', arr.truckCode)
        } else {
          this.$set(this.temp, 'carId', '')
          this.$set(this.temp, 'carNumber', '')
        }
      },
      // 处理仓库数据
      outChange(val) {
        if (!val) {
          return
        }
        const arr = this.storageStoreMap.find((l) => l.storeId === val)
        this.$set(this.temp, 'outStoreId', arr.storeId)
        this.$set(this.temp, 'outStoreName', arr.storeName)
      },
      inChange(val) {
        if (!val) {
          return
        }
        const arr = this.storageStoreMap.find((l) => l.storeId === val)
        this.$set(this.temp, 'inStoreId', arr.storeId)
        this.$set(this.temp, 'inStoreName', arr.storeName)
      },
      reset() {
        this.visible = false
        this.goodsName = ''
        this.temp = {
          transType: 2,
          outStoreId: '',
          inStoreId: '',
          carNumber: '',
          driverId: '',
          escortId: '',
          isSweep: this.temp.isSweep,
          settlementAmount: undefined,
          expectDt: new Date(),
          remark: ''
        }
        this.totalWeight = 0
        this.totalCount = 0
        this.goodsData = {}
        this.lbTableRightwidth = 14
        this.tableRightData.data = []
        this.tableRightData.defaultData = []
        this.$nextTick(() => {
          this.$refs.dataForm.clearValidate()
        })
      }
    }
  }
</script>

<style lang="scss" scoped>
.dataForm {
  .merge-item {
    /deep/ .el-form-item__content {
      display: inline-block;
    }
  }
  // .remark-item {
  //   /deep/ .el-form-item__content {
  //     width: 400px;
  //   }
  // }
}

.el-form-item .el-form-item {
  margin-bottom: 0;
}
.so {
  padding: 10px;
  border: 1px solid #dfdfdf;
}
.leftTree {
  height: 50vh;
}
.aside.open {
  width: auto;
}
.leftTable {
  height: 50vh;
  overflow-y: auto;
}
.rightTable {
  width: 100%;
}
.total {
  margin-top: 10px;
  font-size: 16px;
  font-weight: 600;
  color: #F00;
}
</style>
